package wangm.netty.handler;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.ReplayingDecoder;
import io.netty.handler.codec.http.HttpObject;
import io.netty.util.CharsetUtil;

import java.util.List;

/**
 * describe
 *
 * @author zk
 * @date 2018-02-07 10:19
 */
public class ServerInBoundHandler1 extends SimpleChannelInboundHandler<HttpObject>{
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
        System.out.println("debug point is here");
    }
//    @Override
//    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
//        out.add(in.readInt());
//    }
//    @Override
//    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
//        if(in.readableBytes() < 4){
//            System.out.println("server端检测不足4个字节："+ in.readableBytes());
//            return;
//        }
//        int i = in.readInt();
//        System.out.println("读到int类型:" + i);
//        out.add(i);
//    }
//    @Override
//    protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
//        System.out.println("rec : " + msg);
//    }
//    @Override
//    protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
//        String newMessage = msg.toString(CharsetUtil.UTF_8) + "new!!!!!!!!!";
//        System.out.println("this in bound handler msg is : " + msg.toString(CharsetUtil.UTF_8) + ", type : " + msg.getClass().getTypeName());
//        ctx.fireChannelRead(newMessage);
//    }

//    @Override
//    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
//        ByteBuf byteBuf = (ByteBuf) msg;
//        while(byteBuf.isReadable()){
//            System.out.println("rec:" + byteBuf.readInt());
//        }
//
//    }
}
